local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent());

local ShieldPerfab =CommonOHOH:GetPath_Loop("Resource.Effect.Shield",game.ReplicatedStorage)


function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

    self.player=self.parent.player
    self.player.BattleSateEvent:Connect(function(isEnter)
        if isEnter then
            self:Show()
        else
            self:Hide()
        end
    end)

end;

function M.dtor(self)
	M.super.dtor(self);
end


function M.Show(self)
    self.Shield=ShieldPerfab:Clone()

   
    self.Shield.Parent=self.parent.main_inst
    local startPos= self.Shield:WaitForChild("StartPos")
    local hurt= self.Shield:WaitForChild("hurt")

    local pos=self.parent:GetCFrame():PointToWorldSpace(startPos.Value)
    self.Shield.Position=pos
    hurt.Position=pos
    local root=self.parent:GetRootPart_Check()
    local w=Instance.new("WeldConstraint",hurt)
    w.Part0=hurt
    w.Part1=root
    local attVal= self.Shield:WaitForChild("CharacterCF")
    self.HingeConstraintAtt=Instance.new("Attachment",root)
    self.HingeConstraintAtt.CFrame=attVal.Value
    self.HingeConstraintAtt.Name="Shield"

    local hingeConstraint= self.Shield:WaitForChild("HingeConstraint")
    hingeConstraint.Attachment1= self.HingeConstraintAtt

end


function M.Hide(self)
	if self.Shield then
        self.Shield:Destroy()
        self.HingeConstraintAtt:Destroy()
    end
end


return M

